Return to doc.sitecore.com

Valid for Sitecore 5.3.1
14.  Multilist
Prev Next

The value of "Multilist" field is very similar to the value of "Checklist" field – it is pipe-separated list of IDs of selected items.

The expression below:

<xsl:value-of select="sc:fld('My Multilist', .)"/>

would output something similar to this:

{B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4}|{E473B7A4-6956-4319-B69E-147D91223E4A}

which means that item with ID {B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4} and items with ID {E473B7A4-6956-4319-B69E-147D91223E4A} were selected in multilist field.

You can then parse the string to retrieve individual IDs, get the items identified by the IDs and process them according to the needs of your application. The example below prints "Title" fields of selected items:

<xsl:template match="*" mode="main">
<xsl:variable name="ids" select="concat(sc:fld('My Multilist',.),'|')"/>
<xsl:call-template name="PrintTitles">
  
<xsl:with-param name="ids" select="$ids"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="PrintTitles">
  
<xsl:param name="ids"/>
  
<xsl:if test="$ids">
    
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
    
<xsl:if test="$itm_id">
      
<xsl:variable name="itm" select="sc:item($itm_id,.)"/>
      
<xsl:value-of select="sc:fld('Title', $itm)"/><br/>
    
</xsl:if>
    
<xsl:call-template name="PrintTitles">
      
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
    
</xsl:call-template>
  
</xsl:if>
</xsl:template>

Sample Content Editor input:

Corresponding output in the Preview mode:


Prev Next